package net.servir.diagnostico.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.servir.diagnostico.model.Pregunta;
import net.servir.diagnostico.model.jsp.JspBancoPregunta;
import net.servir.diagnostico.service.DiagnosticoService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class BancoPreguntaController {

	@Autowired
	private DiagnosticoService diagnosticoService;

	@RequestMapping("/bancoPregunta.htm")
	public @ModelAttribute("banco")
	JspBancoPregunta ObtenerPreguntas(HttpServletRequest request,HttpServletResponse response)
	{
		JspBancoPregunta obj = new JspBancoPregunta();
		
		HttpSession session = request.getSession();
		Number idBancoPregunta = 0;
		if(session.getAttribute("BANCO_PREGUNTA") != null)
			idBancoPregunta = Integer.parseInt(session.getAttribute("BANCO_PREGUNTA").toString());
		
		
		List<Pregunta> preguntas = diagnosticoService.obtenerPreguntasPorBanco(idBancoPregunta);		
		obj.setPreguntas(preguntas);
	
		return obj;
	}
}
